package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.beans.Expression;

@Component
@Aspect
public class Advice {

    @Pointcut("execution(* com.itheima.service.impl.StudentServiceImpl.*(..))")
    public void pt(){}

    @Around("pt()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint){
        try {
            long l = System.currentTimeMillis(); //开始时间
            Object[] args = proceedingJoinPoint.getArgs(); //获取被代理对象方法所需要的参数
            String name = proceedingJoinPoint.getSignature().getName(); //获取要执行的被代理对象方法的名字
            Object proceed = proceedingJoinPoint.proceed(args);//执行被代理对象的原方法
            long l1 = System.currentTimeMillis(); //结束时间
            System.out.println("执行"+name+"方法消耗了"+(l1-l)+"毫秒");
            return proceed;//返回方法执行结果
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        } finally {
        }
        return null;
    }
}
